//
//  CZSQLiteManager.swift
//  微博08
//
//  Created by apple on 16/3/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZSQLiteManager: NSObject {
    static let sharedManager = CZSQLiteManager()
    
    let queue: FMDatabaseQueue
    
    override init() {
        let dbPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).last?.stringByAppendingString("/status.db")
        print("dbPath: \(dbPath)")
        
        queue = FMDatabaseQueue(path: dbPath)
        
        super.init()
        createTable("T_Status")
    }
    
    func createTable(tName: String) {
        let sql = "CREATE TABLE IF NOT EXISTS \(tName) (status_id INTEGER NOT NULL PRIMARY KEY, status TEXT, user_id INTEGER, create_at DEFAULT (datetime('now', 'localtime')));"
        
        queue.inDatabase { (db) -> Void in
            if db.executeUpdate(sql) {
                print("创建表成功")
            }
        }
    }
}
